package com.shangting.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shangting.common.entity.FeeKey;
import com.shangting.common.entity.FeeValue;
import com.shangting.web.mapper.FeeKeyMapper;
import com.shangting.web.mapper.FeeValueMapper;
import com.shangting.web.service.FeeKeyService;
import com.shangting.web.vo.fee.FeeKeyVo;
import com.shangting.web.vo.fee.FeeValueVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【fee_key(杂项费用名称表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class FeeKeyServiceImpl extends ServiceImpl<FeeKeyMapper, FeeKey>
        implements FeeKeyService {

    @Autowired
    private FeeKeyMapper feeKeyMapper;

    @Autowired
    private FeeValueMapper feeValueMapper;

    @Override
    public List<FeeKeyVo> getFeeKeyValueList() {
        ArrayList<FeeKeyVo> feeKeyVoList = new ArrayList<>();
        // 获取所有属性名
        List<FeeKey> feeKeys = feeKeyMapper.selectList(null);
        // 获取属性名的所有属性值
        for (FeeKey feeKey : feeKeys) {
            FeeKeyVo feeKeyVo = new FeeKeyVo();
            feeKeyVo.setId(feeKey.getId());
            feeKeyVo.setName(feeKey.getName());
            // 查询属性值
            QueryWrapper<FeeValue> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("fee_key_id", feeKey.getId());
            List<FeeValue> list = feeValueMapper.selectList(queryWrapper);
            ArrayList<FeeValue> feeValueList = new ArrayList<>();
            for (FeeValue feeValue : list) {
                FeeValueVo feeValueVo = new FeeValueVo();
                feeValueVo.setId(feeValue.getId());
                feeValueVo.setName(feeValue.getName());
                feeValueVo.setFeeKeyId(feeKey.getId());
                feeValueVo.setUnit(feeValue.getUnit());
                feeValueList.add(feeValueVo);
            }
            feeKeyVo.setFeeValueList(feeValueList);
            feeKeyVoList.add(feeKeyVo);
        }
        return feeKeyVoList;
    }
}




